package com.example.bigwork.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

// ... 其他import保持不变...
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import javax.sql.DataSource;

@Configuration
@MapperScan(basePackages = "com.example.bigwork.mapper",
           sqlSessionFactoryRef = "sqlSessionFactory")
public class MyBatisConfig {

    @Bean(name = "sqlSessionFactory")
    public SqlSessionFactory sqlSessionFactory(
            DataSource dataSource,
            @Value("${mybatis.mapper-locations}") String mapperLocations) throws Exception {

        SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(dataSource);
        sessionFactory.setTypeAliasesPackage("com.example.bigwork.entity");
        sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
            .getResources(mapperLocations));

        return sessionFactory.getObject(); // 修正返回类型为SqlSessionFactory
    }
}
